@use "../variables" as *;

.history-sidebar {
  width: 0;
  min-width: 0;
  max-height: 100vh;
  height: 100%;
  overflow: hidden;
  transition: width $transition-normal ease, transform $transition-normal ease, min-width $transition-normal ease;
  z-index: $z-sidebar;
  display: flex;
  flex-direction: column;
  background: var(--bg);

  > * {
    white-space: nowrap;
  }

  &.visible {
    width: $sidebar-width;
    min-width: $sidebar-width;
    border-right: 1px solid var(--stroke-gray-medium);
  }

  @media (max-width: $breakpoint-m) {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);

    &.visible {
      transform: translateX(0);
    }
  }

  .history-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 $page-h-padding;

    @include scrollbar;
  }

  .history-star {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 4px;
    padding: 6px 6px 6px 10px;
    font-size: 14px;
    font-weight: 500;
  }

  .history-list-split {
    height: 1px;
    width: 100%;
    background: var(--stroke-gray-medium);
    margin: 16px 0;
  }

  .history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    border-radius: 8px;
    padding: 6px 6px 6px 10px;
    margin-bottom: 4px;

    &.active {
      background: var(--bg-pri-ultraweak);
    }

    &:hover,
    &:has(.sidebar-chat-menu[data-state="open"]) {
      background: var(--bg-gray-medium);

      .sidebar-chat-menu {
        opacity: 1;
      }
    }

    .history-item-loading {
      @include loading-spinner-gradient(16px, 3px, var(--stroke-pri-strong));
      margin-left: 4px;
    }

    .history-content {
      flex: 1;
      min-width: 0;
      margin-right: 8px;

      .history-title {
        font-weight: 500;
        margin-bottom: 2px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }

      .history-date {
        font-size: 12px;
        color: var(--text-weak);
      }
    }

    .sidebar-chat-menu {
      opacity: 0;
      height: 24px;
      width: 24px;
      padding: 4px;
      background: none;
      border: none;
      border-radius: 50%;
      cursor: pointer;
      transition: all $transition-fast;

      &:hover {
        background: var(--bg-gray-strong);
      }

      &[data-state="open"] {
        opacity: 1;
      }

      svg {
        width: 16px;
        height: 16px;
        fill: currentColor;
      }
    }

    .draft-icon {
      width: 16px;
      height: 16px;
      margin-left: 4px;
      color: var(--text-weak);
    }
  }

  .history-header {
    padding: 16px $page-h-padding;

    .new-chat-btn {
      width: 100%;

      > div {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        overflow: hidden;

        span {
          @include line-clamp(1);
          display: inline-block;
        }
      }

      svg {
        fill: none;
      }
    }
  }

  .sidebar-footer {
    margin-top: auto;
    padding: 16px;
    border-top: 1px solid var(--stroke-gray-medium);

    .sidebar-footer-btn {
      display: flex;
      align-items: center;
      gap: 8px;
      width: 100%;
      padding: 8px 12px;
      border: none;
      border-radius: 6px;
      background: none;
      color: inherit;
      cursor: pointer;
      transition: all $transition-fast;
      line-height: 24px;

      &:hover {
        background: var(--bg-gray-op-medium);
      }

      &:focus {
        outline: none;
      }

      svg {
        fill: none;
        color: var(--text-strong);

        &.filter {
          fill: currentColor;
        }
      }

      .oap-user-info {
        display: flex;
        align-items: center;
        gap: 8px;
        line-height: 20px;
      }

      .oap-avatar {
        width: 20px;
        height: 20px;
        border-radius: 50%;
      }

      .oap-username {
        max-width: 138px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }

      .oap-label {
        display: flex;
        align-items: center;
        gap: 8px;
      }

      .oap-level {
        display: flex;
        align-items: center;
        gap: 4px;
        color: var(--text-pri);
        font-weight: 600;
        font-size: 16px;
      }
    }

    .sidemenu-btn {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
      width: 100%;

      &:hover {
        background: unset;
      }
    }
  }
}

.sidebar-chat-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;

  svg {
    width: 22px;
    height: 22px;
    color: var(--text-weak);
  }
}

.popup-confirm {
  &.delete-confirm-modal {
    .popup-confirm-header {
      h3 {
        margin: 0;
      }
    }
    .popup-confirm-content {
      padding: 0;
      color: var(--text-medium);
    }
  }

  &.rename-confirm-modal {
    width: 500px;
    padding: 0 30px;

    .rename-confirm-modal-content {
      width: 100%;
    }

    .popup-confirm-header {
      h3 {
        margin: 0;
      }
    }
  }

  &.mcp-install-confirm-modal {
    padding: 15px;
  }
}